Skip to content

[stable33] fix(preview): qualify the ambiguous columns in PreviewMapper queries - #63346

Open
backportbot[bot] wants to merge 1 commit into
stable33from
backport/63286/stable33
Open

[stable33] fix(preview): qualify the ambiguous columns in PreviewMapper queries#63346
backportbot[bot] wants to merge 1 commit into
stable33from
backport/63286/stable33

Conversation

@backportbot

@backportbot backportbot Bot commented Aug 18, 2026

Copy link
Copy Markdown

Backport of #63286

Warning, This backport's changes differ from the original and might be incomplete ⚠️

Todo

  • Review and resolve any conflicts
  • Review and verify the backported changes
  • Amend HEAD commit to remove the line stating to skip CI

Learn more about backports at https://docs.nextcloud.com/server/stable/go.php?to=developer-backports.

@szaimen

szaimen commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

@solracsf Are we sure this affects 33 as well?

@solracsf

This comment was marked as outdated.

@solracsf solracsf closed this Aug 18, 2026
@solracsf
solracsf deleted the backport/63286/stable33 branch August 18, 2026 07:52
@Oriann

Oriann commented Aug 18, 2026

Copy link
Copy Markdown

@solracsf Are we sure this affects 33 as well?

Yes it does: @solracsf @szaimen

nextcloud.log
Nextcloud: 33.0.8.2
Preview Generator: 5.14.0
Database: MariaDB/MySQL
Background jobs: cron

Error while running background job
OCA\PreviewGenerator\BackgroundJob\PreviewJob
(id: 118479, arguments: null)

OC\DB\Exceptions\DbalException:

An exception occurred while executing a query:
SQLSTATE[23000]: Integrity constraint violation:
1052 Column 'file_id' in WHERE is ambiguous

Doctrine exception:
Doctrine\DBAL\Exception\NonUniqueFieldNameException

Relevant stack trace:

#0  lib/private/DB/ConnectionAdapter.php:53
    OC\DB\Exceptions\DbalException::wrap()

#1  lib/private/DB/QueryBuilder/QueryBuilder.php:268
    OC\DB\ConnectionAdapter->executeQuery()

#2  lib/public/AppFramework/Db/QBMapper.php:276
    OC\DB\QueryBuilder\QueryBuilder->executeQuery()

#3  lib/public/AppFramework/Db/QBMapper.php:382
    OCP\AppFramework\Db\QBMapper->findOneQuery()

#4  lib/private/Preview/Db/PreviewMapper.php:241
    OCP\AppFramework\Db\QBMapper->findEntity()

#5  lib/private/Preview/Generator.php:604
    OC\Preview\Db\PreviewMapper->getPreviewForSpecification()

#6  lib/private/Preview/Generator.php:565
    OC\Preview\Generator->savePreview()

#7  lib/private/Preview/Generator.php:183
    OC\Preview\Generator->generatePreview()

#8  lib/private/PreviewManager.php:185
    OC\Preview\Generator->generatePreviews()

#9  apps/previewgenerator/lib/Service/PreGenerateService.php:160
    OC\PreviewManager->generatePreviews()

#10 apps/previewgenerator/lib/Service/PreGenerateService.php:141
    OCA\PreviewGenerator\Service\PreGenerateService->processFile()

#11 apps/previewgenerator/lib/Service/PreGenerateService.php:110
    OCA\PreviewGenerator\Service\PreGenerateService->processRow()

#12 apps/previewgenerator/lib/Service/PreGenerateService.php:73
    OCA\PreviewGenerator\Service\PreGenerateService->startProcessing()

#13 apps/previewgenerator/lib/BackgroundJob/PreviewJob.php:61
    OCA\PreviewGenerator\Service\PreGenerateService->preGenerate()

#14 lib/public/BackgroundJob/Job.php:50
    OCA\PreviewGenerator\BackgroundJob\PreviewJob->run()

#15 lib/public/BackgroundJob/TimedJob.php:85
#16 core/Service/CronService.php:176
#17 core/Service/CronService.php:98
#18 cron.php:52

@solracsf
solracsf restored the backport/63286/stable33 branch August 18, 2026 14:28
@solracsf solracsf reopened this Aug 18, 2026
joinLocation() joins previews (p) with preview_locations (l) and
preview_versions (v). Both previews and preview_versions have a file_id
column, so any unqualified file_id condition is ambiguous and MySQL or
MariaDB reject the query with error 1052.

getPreviewForSpecification() built its conditions straight from the
caller's array keys, so this broke every preview save: savePreview() uses
that lookup to recover the existing row after a unique constraint
violation. getByFileId() had the same unqualified condition, while
getAvailablePreviewsForFile() next to it already used p.file_id.

Columns that come from the joined tables keep resolving to their own
alias, and keys that already carry one are passed through untouched.
The values are bound with an explicit type as well. An untyped false
binds as an empty string, which PostgreSQL rejects for a boolean column,
so qualifying the columns on their own only moved the error on that
backend.

Fixes: #63229
Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
@CarlSchwan
CarlSchwan force-pushed the backport/63286/stable33 branch from f938834 to b5222a1 Compare August 18, 2026 14:32
@solracsf
solracsf marked this pull request as ready for review August 18, 2026 14:33
@solracsf
solracsf requested a review from a team as a code owner August 18, 2026 14:33
@solracsf
solracsf requested review from icewind1991, leftybournes, provokateurin and salmart-dev and removed request for a team August 18, 2026 14:33

@szaimen szaimen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐘

@joshtrichards joshtrichards added 4. to release Ready to be released and/or waiting for tests to finish and removed 3. to review Waiting for reviews labels Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4. to release Ready to be released and/or waiting for tests to finish bug feature: previews and thumbnails

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants